package com.example.hp.yuejian5.model;

import com.example.hp.yuejian5.RetrofitListener.RetrofitListener;
import com.example.hp.yuejian5.bean.TrainorderBean;
import com.example.hp.yuejian5.service.TrainorderService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.hp.yuejian5.other.url.INDEXURL;

public class TrainorderModel {
    protected Retrofit retrofit;
    protected TrainorderService orderService;
    public TrainorderModel()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(INDEXURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        orderService=retrofit.create(TrainorderService.class);
    }
    public void Trainorder(String train_id,String user_id,String realname,String tel,String num,String mode,final RetrofitListener listener)
    {

        Call<TrainorderBean> call= orderService.order(train_id,user_id,realname,tel,num,mode);
        call.enqueue(new Callback<TrainorderBean>() {
            @Override
            public void onResponse(Call<TrainorderBean> call, Response<TrainorderBean> response) {
                listener.onSuccess(response.body(),1);
            }
            @Override
            public void onFailure(Call<TrainorderBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }

}
